#!/usr/bin/env bash

set -e

cd "$(dirname "$0")/.."

if [ -f "Brewfile" ] && [ "$(uname -s)" = "Darwin" ] && [ "$SKIP_BREW" != "1" ] && [ -t 0 ]; then
  brew bundle check >/dev/null 2>&1 || {
    echo -n "==> Install Homebrew dependencies? (y/N): "
    read -r response
    case "$response" in
      [yY][eE][sS]|[yY])
        brew bundle
        ;;
      *)
        ;;
    esac
    echo
  }
fi
echo "==> Installing Go dependencies…"

# Set GOPRIVATE if the repository appears to be private
REPO_STATUS=$(curl -s -o /dev/null -w "%{http_code}" https://github.com/cloudflare/cloudflare-go)
if [ "$REPO_STATUS" = "404" ]; then
  export GOPRIVATE=github.com/cloudflare/cloudflare-go
fi
go mod tidy -e || true
